﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AZShop.Macros.Tests.Helpers;
using AZShop.Macros.DataAccess;

namespace AZShop.Macros.Tests.DataAccess
{
    /// <summary>
    /// Summary description for ProductRepositoryTest
    /// </summary>
    [TestClass]
    public class ProductRepositoryTest
    {
        public ProductRepositoryTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        [ClassInitialize()]
        public static void MyClassInitialize(TestContext testContext) { 
        }

        //
        // Use ClassCleanup to run code after all tests in a class have run
        [ClassCleanup()]
        public static void MyClassCleanup() {
            DatabaseHelper.CleanupDatabase();
        }
        //
        // Use TestInitialize to run code before running each test 
        [TestInitialize()]
        public void MyTestInitialize() {
            DatabaseHelper.InitializeDatabase();
        }
        //
        // Use TestCleanup to run code after each test has run
        [TestCleanup()]
        public void MyTestCleanup() {
            DatabaseHelper.CleanupDatabase();
        }
        //
        #endregion

        [TestMethod]
        public void GetProductsByDateTest()
        {
            ProductRepository pr = new ProductRepository();
            IList<CSK_Store_Product> actual = pr.GetProductsByDate(1);

            Assert.AreNotEqual(0, actual.Count);

            CSK_Store_Product product = actual.Where(p => p.productName == "IPhone 3GS").FirstOrDefault();
            Assert.IsNotNull(product);
            Assert.AreEqual("IPHONE 3GS", product.sku);
        }
    }
}
